import numpy as np 
import matplotlib.pyplot as plt
import Neural_NetWorks.Model as Model
import Neural_NetWorks.Lost as Lost
import Neural_NetWorks.Activation as Activation
import Neural_NetWorks.Layer as Layer




data = np.loadtxt("DataSet\\breast-cancer.csv",delimiter=",",skiprows=1)

# TrainingData = data[:-69]
TrainingData = data[:-69]  
TestData = data[-69:]


x = TrainingData[:,1:] 
y = TrainingData[:,0].reshape(-1,1)

x_avager = np.average(x,axis=0) 
x_max = np.max(x,axis=0) 
x_min = np.min(x,axis=0)
x = (x-x_avager)/(x_max-x_min) 
FeatureSize = x.shape[1]

 
learning_rate = 0.1


model = Model.Model()
model.Load("model1.MH5")

# model.add(Layer.Dense(40,FeatureSize,Activation.Relu()))
# model.add(Layer.Dense(20,40,Activation.Sigmoid()))
# model.add(Layer.Dense(1,20,Activation.Sigmoid()))
# model.Compile(Lost.BinaryCrossentropy(),learning_rate)

# costlist = []
# # for datax ,datay in zip(x,y):
# #     cost =  model.fit_Batchones(datax.reshape(-1,FeatureSize),datay.reshape(-1,1))
# #     costlist.append(cost)
# for  i in range(100):
#     cost = model.fit_Batchones(x,y)
#     print(f"epoch:{i},cost:{cost:.4f}")
#     costlist.append(cost)
  
# plt.plot(costlist)
# model.Save("model1.MH5")

test_x = TestData[:,1:]
test_x = (test_x-x_avager)/(x_max-x_min)

print(test_x.shape)
test_y = TestData[:,0].reshape(-1,1)
test_res = model.Prediction(test_x)

print(test_res)
r = ((np.any(test_res>0.5,axis=1).reshape(-1,1) == test_y))
print(np.sum(r!=False)/len(r))
plt.show()




